package com.damuzee.core.web.springmvc;

import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
import org.springframework.web.servlet.view.AbstractUrlBasedView;

/**
 * ViewResolver for RichFreeMarkerView
 * 
 * 重写构建试图方法,如果视图是以/开头的话,就忽略prefix.
 * 
 * @author karkaw
 **/

public class RichFreeMarkerViewResolver extends AbstractTemplateViewResolver {

	private String root = "";

	/**
	 * 设置缺省的viewClass
	 */
	public RichFreeMarkerViewResolver() {
		setViewClass(RichFreeMarkerView.class);
	}

	/**
	 * 如果视图是以"/"开头的话,就忽略prefix.
	 */
	protected AbstractUrlBasedView buildView(String viewName) throws Exception {
		AbstractUrlBasedView view = super.buildView(viewName);

		if (viewName.startsWith("/")) {
			view.setUrl(root + viewName + getSuffix());
		}
		System.out.println(viewName);
		return view;
	}

	public String getRoot() {
		return root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

}
